home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 …ember: Reference Library / Dev.CD Dec 96 RL / Dev.CD Dec 96 RL.toast / Technical Documentation / develop / develop Issue 28 / develop Issue 28 code / MacApp Debugging / TwistDownLists / UTwistDownApp.cp < prev    next >
Encoding:
Text File  |  1996-09-23  |  58.4 KB  |  1,872 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UTwistDownApp.cp
  3. // ETO20 MacApp 3.3.1, MPW 3.4.1
  4. // Copyright ©1994-1996 Conrad Kopala
  5. // Twist Down Lists version 2.0a0 7/15/96
  6. //----------------------------------------------------------------------------------------
  7.  
  8. #ifndef __UTWISTDOWNAPP__
  9. #include "UTwistDownApp.h"
  10. #endif
  11.  
  12. #ifndef __UTWISTDOWNDOCUMENT__
  13. #include "UTwistDownDocument.h"
  14. #endif
  15.  
  16. #ifndef __UTWISTDOWNELEMENT__
  17. #include "UTwistDownElement.h"
  18. #endif
  19.  
  20. #ifndef __UTWISTDOWNCONTROL__
  21. #include "UTwistDownControl.h"
  22. #endif
  23.  
  24. #ifndef __UTWISTDOWNVIEW__
  25. #include "UTwistDownView.h"
  26. #endif
  27.  
  28. //MacApp stuff
  29. #ifndef __UAPPLEEVENTS__
  30. #include "UAppleEvents.h"        //PPC
  31. #endif
  32.  
  33. #ifndef __UCLIPBOARDMGR__
  34. #include "UClipboardMgr.h"        //PPC
  35. #endif
  36.  
  37. #ifndef __UDEBUG__
  38. #include "UDebug.h"        //PPC
  39. #endif
  40.  
  41. #ifndef __UDIALOG__
  42. #include "UDialog.h"
  43. #endif
  44.  
  45. #ifndef __UDIALOGBEHAVIOR__
  46. #include "UDialogBehavior.h"
  47. #endif
  48.  
  49. #ifndef __UERRORMGR__
  50. #include "UErrorMgr.h"        //PPC    messageNewFailed
  51. #endif
  52.  
  53. #ifndef __UFAILURE__
  54. #include "UFailure.h"        //PPC
  55. #endif
  56.  
  57. #ifndef __UMENUMGR__
  58. #include "UMenuMgr.h"
  59. #endif
  60.  
  61. #ifndef __OBJECTHEAP__
  62. #include "ObjectHeap.h"        //for MacApp 3.5
  63. #endif
  64.  
  65. #ifndef __USCRIPTING__
  66. #include "UScripting.h"    //PPC gMacAppAppleEventIdleProc
  67. #endif
  68.  
  69. #ifndef __UVIEWSERVER__
  70. #include "UViewServer.h"
  71. #endif
  72.  
  73. #ifndef __UWINDOW__
  74. #include "UWindow.h"
  75. #endif
  76.  
  77. #ifndef __UCLASSDESC__
  78. #include "UClassDesc.h"
  79. #endif
  80.  
  81. #ifndef __UCLASSDESCITERATOR__
  82. #include "UClassDescIterator.h"
  83. #endif
  84.  
  85. //ToolBox stuff
  86.  
  87. #ifndef __AEREGISTRY__
  88. #include "AERegistry.h"
  89. #endif
  90.  
  91. #ifndef __FONTS__            //required for the diamondMark used in the Windows menu
  92. #include "Fonts.h"
  93. #endif
  94.  
  95. #ifndef __MENUS__
  96. #include "Menus.h"
  97. #endif
  98.  
  99. #ifndef __RESOURCES__
  100. #include "Resources.h"
  101. #endif
  102.  
  103. //ANSI stuff
  104. //None
  105.  
  106. //----------------------------------------------------------------------------------------
  107. //gGlobals:
  108. TTwistDownApp* gTwistDownApp;
  109.  
  110. //----------------------------------------------------------------------------------------
  111. // Constants:
  112.  
  113.  
  114.         
  115. //========================================================================================
  116. // CLASS CWindowsMenuListIterator
  117. //========================================================================================
  118. #undef Inherited
  119.  
  120. //----------------------------------------------------------------------------------------
  121. // CWindowsMenuListIterator::CWindowsMenuListIterator: 
  122. //----------------------------------------------------------------------------------------
  123. #pragma segment MAApplicationRes
  124. CWindowsMenuListIterator::CWindowsMenuListIterator(TTwistDownApp* itsApplication,
  125.                                      ArrayIndex itsLowBound, ArrayIndex itsHighBound, Boolean itsForward) :
  126. CObjectIterator(itsApplication ? itsApplication->fWindowsMenuList : NULL, 
  127.                                     itsLowBound, itsHighBound, itsForward)
  128.  
  129. {
  130. //not used, could take out?
  131. //----------------------------------------------------------------------------------------
  132. // CWindowsMenuListIterator::CWindowsMenuListIterator: 
  133. //----------------------------------------------------------------------------------------
  134. #pragma segment MAApplicationRes
  135. CWindowsMenuListIterator::CWindowsMenuListIterator(TTwistDownApp* itsApplication,
  136.                                      Boolean itsForward) :
  137.     CObjectIterator(itsApplication ? itsApplication->fWindowsMenuList : NULL, itsForward)
  138. {
  139. //not used, could take out?
  140. }
  141. //----------------------------------------------------------------------------------------
  142. // CWindowsMenuListIterator::CWindowsMenuListIterator: 
  143. //----------------------------------------------------------------------------------------
  144. #pragma segment MAApplicationRes
  145. CWindowsMenuListIterator::CWindowsMenuListIterator(TTwistDownApp* itsApplication) :
  146.     CObjectIterator(itsApplication ? itsApplication->fWindowsMenuList : NULL)
  147. {
  148. //used
  149. }
  150. //----------------------------------------------------------------------------------------
  151. // CWindowsMenuListIterator::~CWindowsMenuListIterator: 
  152. //----------------------------------------------------------------------------------------
  153. #pragma segment IteratorRes
  154. CWindowsMenuListIterator::~CWindowsMenuListIterator()
  155. {
  156.  
  157. }
  158. //----------------------------------------------------------------------------------------
  159. // CWindowsMenuListIterator::CurrentWindow: 
  160. //----------------------------------------------------------------------------------------
  161. #pragma segment MAApplicationRes
  162. TWindow* CWindowsMenuListIterator::CurrentWindow()
  163. {
  164.     return (TWindow*)this->CurrentObject();
  165. }
  166. //----------------------------------------------------------------------------------------
  167. // CWindowsMenuListIterator::FirstWindow: 
  168. //----------------------------------------------------------------------------------------
  169. #pragma segment MAApplicationRes
  170. TWindow* CWindowsMenuListIterator::FirstWindow()
  171. {
  172.     return (TWindow*)this->FirstObject();
  173. }
  174. //----------------------------------------------------------------------------------------
  175. // CWindowsMenuListIterator::NextWindow: 
  176. //----------------------------------------------------------------------------------------
  177. #pragma segment MAApplicationRes
  178. TWindow* CWindowsMenuListIterator::NextWindow()
  179. {
  180.     return (TWindow*)this->NextObject();
  181. }
  182.  
  183. //========================================================================================
  184. // CLASS TTwistDownApp
  185. //========================================================================================
  186. #undef Inherited
  187. #define Inherited TApplication
  188.  
  189. #pragma segment MAInit
  190. MA_DEFINE_CLASS_M2(TTwistDownApp, Inherited, MVolumeBasedApp);
  191. //----------------------------------------------------------------------------------------
  192. // TTwistDownApp::TTwistDownApp
  193. //----------------------------------------------------------------------------------------
  194. #pragma segment MAInit
  195. TTwistDownApp::TTwistDownApp() : MVolumeBasedApp()
  196. {
  197.  
  198. gTwistDownApp = this;
  199. gSendAppleEvents = TRUE;
  200. gUseSystemDirection = TRUE;
  201. gAppleEventRouting = routeToDoc;
  202.  
  203. fMainFileType = kFileType;
  204. fLaunchWithNewDocument = FALSE;
  205.  
  206. fHasSplashScreen = !kHasSplashScreen;    //For openers, assume no splash screen.
  207.  
  208. fWindowsMenuList = NULL;
  209. fShowInvisibleFiles = FALSE;
  210.  
  211. fAllowUnlimitedDocs = FALSE;
  212.  
  213. fTDElementClassSize = 0;    //the class size of TTwistDownElement
  214. fTDControlClassSize = 0;    //the class size of TTwistDownControl
  215.  
  216. #if qDebug
  217. this -> PrintAppConstructorClassInfo();
  218. #endif
  219.  
  220. }
  221. //----------------------------------------------------------------------------------------
  222. // TTwistDownApp::~TTwistDownApp
  223. //----------------------------------------------------------------------------------------
  224. #pragma segment MADestructorRes
  225. TTwistDownApp::~TTwistDownApp()
  226. {
  227.  
  228. fWindowsMenuList = (TList*)FreeListIfObject(fWindowsMenuList);
  229.  
  230. #if qDebug
  231. this -> PrintAppDestructorClassInfo();
  232. #endif
  233.  
  234. }
  235. //----------------------------------------------------------------------------------------
  236. // TTwistDownApp::ITwistDownApp: 
  237. //----------------------------------------------------------------------------------------
  238. #pragma segment MAInit
  239. void TTwistDownApp::ITwistDownApp(Boolean hasSplashScreen)
  240. {
  241.     this -> IApplication(kFileType, kSignature);
  242.  
  243. fHasSplashScreen = hasSplashScreen;
  244.  
  245.     fWindowsMenuList = NewList();
  246. #if qDebug
  247.     fWindowsMenuList->SetEltType("TWindow");
  248. #endif
  249.     
  250.     AppendResMenu(MAGetMenu(mFontMenu), 'FONT');
  251.  
  252. //The class size of TTwistDownElement and TTwistDownControl is used to determine
  253. //if there is enough space in the object heap to open a volume. Get their class sizes
  254. //now and save them, because later on when they're needed, there may not be enough space 
  255. //left in the ObjectHeap to do it.
  256.  
  257. TTwistDownElement* twistDownElement = new TTwistDownElement;
  258. CStr63 displayedText = gEmptyString;
  259. twistDownElement -> ITwistDownElement(NULL, 0, displayedText);
  260. fTDElementClassSize = (short)(twistDownElement -> GetClassSize());
  261. twistDownElement = (TTwistDownElement*)FreeIfObject(twistDownElement);
  262.  
  263. TTwistDownControl* twistDownControl = new TTwistDownControl;
  264. VPoint itsLocation = gZeroVPt;
  265. twistDownControl -> ITwistDownControl(itsLocation, NULL,NULL);
  266. fTDControlClassSize = (short)(twistDownControl -> GetClassSize());
  267. twistDownControl = (TTwistDownControl*)FreeIfObject(twistDownControl);
  268.  
  269. //Note: If IApplication can post a TEventRetrieverCommand, I can post 
  270. //a TSplashScreenCommand here too.
  271. if (fHasSplashScreen)
  272.     {
  273.         TSplashScreenCommand* aSplashScreenCommand = NULL;
  274.  
  275.         aSplashScreenCommand = new TSplashScreenCommand;
  276.         aSplashScreenCommand -> ISplashScreenCommand(cSplashScreen);
  277.         this -> PostCommand(aSplashScreenCommand);
  278.     }
  279.  
  280. }
  281. //----------------------------------------------------------------------------------------
  282. // TTwistDownApp::GetNextDocumentNumber: used by TTwistDownDocument::SetVolumeData:
  283. //----------------------------------------------------------------------------------------
  284. //Twist Down Lists can open the same volume many times. The following method is used to determine
  285. //the number of times a given volume has been opened. It returns a count of the number of times
  286. //a given volume has been opened plus 1. That value is used by 
  287. //TTwistDownDocument::SetVolumeData(short volumeRefNumber, CStr31 volumeName)
  288. //to establish a unique document title. Note that scripting support requires that
  289. //documents have unique titles. 
  290. #pragma segment AOpen
  291. short TTwistDownApp::GetNextDocumentNumber(const CStr31& volumeName)
  292. {
  293.     
  294.     short sameDocumentCount = 0;
  295.     short highestSameDocumentNumber = 0;
  296.     
  297.     CDocumentIterator iter(this);
  298.  
  299.     for (TDocument * aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
  300.         {
  301.             TTwistDownDocument* aTwistDownDocument = (TTwistDownDocument*)aDocument;
  302.             CStr31 itsVolumeName = aTwistDownDocument -> fVolumeName;
  303.             
  304.             if (itsVolumeName == volumeName)
  305.                 {
  306.                     sameDocumentCount++;
  307.                     short thisSameDocumentNumber = aTwistDownDocument -> fSameVolumeNumber;
  308.                     if (thisSameDocumentNumber > highestSameDocumentNumber)
  309.                         highestSameDocumentNumber = thisSameDocumentNumber;
  310.                 }
  311.         }
  312.     
  313.     if (sameDocumentCount == 0)
  314.         return sameDocumentCount + 1;
  315.     else
  316.         return highestSameDocumentNumber + 1;
  317. }
  318.  
  319. //----------------------------------------------------------------------------------------
  320. // TTwistDownApp::FindDocument:        //analog of FindDocument, overloaded
  321. //----------------------------------------------------------------------------------------
  322. #pragma segment MAFile
  323. TDocument* TTwistDownApp::FindDocument(TVolume* aVolume)
  324. {
  325.  
  326.     CDocumentIterator iter(this);
  327.  
  328.     for (TDocument * aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
  329.         {
  330.             TTwistDownDocument* aTwistDownDocument = (TTwistDownDocument*)aDocument;
  331.             if (aTwistDownDocument -> FindDocument(aVolume))
  332.                 return aDocument;
  333.         }
  334.     return NULL;                                // No document already open
  335.  
  336. }
  337. //----------------------------------------------------------------------------------------
  338. // TTwistDownApp::DoMakeDocument: overloaded
  339. //----------------------------------------------------------------------------------------
  340. #pragma segment AOpen
  341. TDocument* TTwistDownApp::DoMakeDocument(CommandNumber aCommandNumber, TVolume* itsVolume)
  342. {
  343. #pragma unused aCommandNumber
  344.     TTwistDownDocument* aTwistDownDocument = NULL;
  345.  
  346.     aTwistDownDocument = new TTwistDownDocument;
  347.     aTwistDownDocument -> ITwistDownDocument(itsVolume, fShowInvisibleFiles);
  348.  
  349.     return aTwistDownDocument;
  350.  
  351. }
  352. //----------------------------------------------------------------------------------------
  353. //    TTwistDownApp::DoSetupMenus    
  354. //----------------------------------------------------------------------------------------
  355. #pragma segment ARes
  356. void TTwistDownApp::DoSetupMenus()
  357. {
  358.  
  359. #if qDebug
  360. if (gAppUserFlag3)
  361.     {
  362.     fprintf(stderr, ">TTwistDownApp::DoSetupMenus upon entry\n");
  363.     PrintObjectCount();
  364.     fprintf(stderr, "\n");
  365.     DisplayMemoryInfo();
  366.     }
  367. #endif
  368.     
  369.     MenuRef theWindowsMenuRef = NULL;
  370.     
  371.     short theNumberOfWindows = 0;
  372.     
  373.     CWindowsMenuListIterator iter(this);
  374.     CStr255 theTitle = " ";
  375.     CStr255 dummyTitle = "Dummy Title";
  376.     short theMenuItem = 0;
  377.     
  378.     short counter = 0;
  379.     
  380.     Inherited::DoSetupMenus();
  381.  
  382.     Enable(cNew, FALSE);
  383.     EnableCheck(cShowInvisibleFiles,TRUE, fShowInvisibleFiles);
  384.     
  385.     Boolean haveMemory = !MemSpaceIsLow();
  386.     Enable(cOpen, haveMemory);
  387.  
  388.     theWindowsMenuRef = MAGetMenu(mWindowsMenu);
  389.     LockHandle((Handle)theWindowsMenuRef);    
  390.     if(theWindowsMenuRef != NULL)
  391.         theNumberOfWindows = CountMItems(theWindowsMenuRef);
  392.     
  393.     //first get rid of all the windows in the menu
  394.     
  395.     if (theNumberOfWindows != 0)
  396.         for (counter = 1; counter <= theNumberOfWindows; counter++)
  397.         {
  398.             DeleteMenuItem(theWindowsMenuRef, 1);
  399.             DisableItem(theWindowsMenuRef, 31);
  400.         }
  401.  
  402.     //now, put them in    
  403.     theNumberOfWindows = this -> CountWindowsInList();
  404.     
  405.     if (theNumberOfWindows != 0)
  406.         for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
  407.             {
  408.                 theMenuItem++;
  409.                 aWindow -> GetTitle(theTitle);
  410.                 AppendMenu(theWindowsMenuRef, dummyTitle);        //in Menus.h
  411.                 SetMenuItemText(theWindowsMenuRef, theMenuItem, theTitle);    //in Menus.h
  412.                 EnableItem(theWindowsMenuRef, theMenuItem);
  413.                 if (aWindow == this -> GetActiveWindow(kNoFloaters))
  414.                     SetItemMark(theWindowsMenuRef, theMenuItem, diamondMark);                    
  415.             }
  416.     HUnlock((Handle)theWindowsMenuRef);
  417.     
  418.     
  419.     EnableCheck(cFailHere,TRUE, gFailHere);
  420.     EnableCheck(cAllowUnlimitedDocs, TRUE, fAllowUnlimitedDocs);
  421.     EnableCheck(cUseSystemDirection, TRUE, gUseSystemDirection );
  422.     EnableCheck(cSendAppleEvents, TRUE, gSendAppleEvents);
  423.  
  424. //Note: Though the cWritingDirection command is not accessible here, I want it to always be
  425. //in a known state. Without the following, the menuName seen by the user remains whatever
  426. //it was changed to by the last cWritingdirection command. Instances of TTwistDownView control
  427. //the command name seen for this item. However, if a twistDownView set it to Right-To-Left and
  428. //it is closed leaving no instance of TTwistDownView, then the command name seen for this item
  429. //would remain Right-To-Left. That is mightily disconcerting and, at first, you think the
  430. //application is acting up. Here we do make it behave consistently.
  431.  
  432. if (GetSysDirection() == 0)
  433.     SetIndividualCommandName(cWritingDirection, kMenuNameStrings, kRightToLeftNameIdx);
  434. else
  435.     SetIndividualCommandName(cWritingDirection, kMenuNameStrings, kLeftToRightNameIdx);
  436.     
  437. if (gAppleEventRouting == routeToDoc)
  438.     SetIndividualCommandName(cAppleEventRouting, kMenuNameStrings, kRouteToViewNameIdx);
  439. else
  440.     SetIndividualCommandName(cAppleEventRouting, kMenuNameStrings, kRouteToDocNameIdx);
  441.  
  442.     
  443. Enable(cAppleEventRouting, gSendAppleEvents);
  444.     
  445. #if qDebug
  446.     EnableCheck(cCountObjects, TRUE, gObjectCountingEnabled);
  447.     Enable(cResetObjectCount, TRUE);
  448.     EnableCheck(cPrintBaseClassInfo, TRUE, gPrintBaseClassInfo);    
  449.     EnableCheck(cPrintMacAppClassInfo, TRUE, gPrintMacAppClassInfo);    
  450.     EnableCheck(cPrintAppClassInfo, TRUE, gPrintAppClassInfo);    
  451.     EnableCheck(cAppUserFlag1, TRUE, gAppUserFlag1);
  452.     EnableCheck(cAppUserFlag2, TRUE, gAppUserFlag2);
  453.     EnableCheck(cAppUserFlag3, TRUE, gAppUserFlag3);    
  454. #endif
  455.  
  456. }
  457. //----------------------------------------------------------------------------------------
  458. //    TTwistDownApp::DoMenuCommand    
  459. //----------------------------------------------------------------------------------------
  460. #pragma segment ASelCommand
  461. void TTwistDownApp::DoMenuCommand(CommandNumber aCommandNumber)
  462. {
  463. short theMenu = 0;
  464. short theMenuItem = 0;
  465. TWindow* newFrontWindow = NULL;
  466.  
  467. CommandToMenuItem(aCommandNumber, theMenu, theMenuItem);    
  468.  
  469. if (theMenu == mWindowsMenu)
  470.     {
  471.         newFrontWindow = (TWindow*)fWindowsMenuList -> At(theMenuItem);
  472.         if (newFrontWindow != (gApplication->GetActiveWindow(kNoFloaters)))
  473.             newFrontWindow -> Select();
  474.     }
  475. else
  476.         switch (aCommandNumber) 
  477.             {
  478.                 case cShowInvisibleFiles:
  479.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  480.                         {
  481.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  482.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pShowInvisibleFiles);
  483.                             CTempDesc theNewValue;
  484.                             theNewValue.PutBoolean(!fShowInvisibleFiles);
  485.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  486.                             TAppleEvent * theReply = theEvent -> Send();
  487.                             FreeIfObject(theEvent);
  488.                             FreeIfObject(theReply);
  489.                         }
  490.                     else
  491.                         fShowInvisibleFiles = !fShowInvisibleFiles;
  492.                 break;            
  493.             
  494.                 case cFailHere:
  495.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  496.                         {
  497.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  498.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pFailHere);
  499.                             CTempDesc theNewValue;
  500.                             theNewValue.PutBoolean(!gFailHere);
  501.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  502.                             TAppleEvent * theReply = theEvent -> Send();
  503.                             FreeIfObject(theEvent);
  504.                             FreeIfObject(theReply);
  505.                         }
  506.                     else
  507.                         gFailHere = !gFailHere;
  508.                 break;
  509.                 
  510.                 case cAllowUnlimitedDocs:
  511.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  512.                         {
  513.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  514.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pUnlimitedDocs);
  515.                             CTempDesc theNewValue;
  516.                             theNewValue.PutBoolean(!fAllowUnlimitedDocs);
  517.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  518.                             TAppleEvent * theReply = theEvent -> Send();
  519.                             FreeIfObject(theEvent);
  520.                             FreeIfObject(theReply);
  521.                         }
  522.                     else
  523.                         fAllowUnlimitedDocs = !fAllowUnlimitedDocs;
  524.                 break;                
  525.                 
  526.                 case cSendAppleEvents:
  527.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() /*&& gSendAppleEvents*/)
  528.                         {
  529.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  530.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pSendAppleEvents);
  531.                             CTempDesc theNewValue;
  532.                             theNewValue.PutBoolean(!gSendAppleEvents);
  533.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  534.                             TAppleEvent * theReply = theEvent -> Send();
  535.                             FreeIfObject(theEvent);
  536.                             FreeIfObject(theReply);
  537.                         }
  538.                     else
  539.                         gSendAppleEvents = !gSendAppleEvents;                        
  540.                 break;
  541.  
  542. //Question: If gUseSystemDirection == FALSE, some twistDownViews may be in right-to-left
  543. //while others are in left-to-right. When the user changes gUseSystemDirection to TRUE,
  544. //should those TTwistDownViews that are not currently using the system direction be
  545. //changed to use it? At present, they don't change and they're locked in what ever
  546. //writing direction they were using when gUseSystemDirection was changed to TRUE.
  547.                 case cUseSystemDirection:
  548.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  549.                         {
  550.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  551.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pUseSystemDirection);
  552.                             CTempDesc theNewValue;
  553.                             theNewValue.PutBoolean(!gUseSystemDirection);
  554.                             theEvent -> WriteParameter(keyAEData, theNewValue);    
  555.                             TAppleEvent * theReply = theEvent -> Send();
  556.                             FreeIfObject(theEvent);
  557.                             FreeIfObject(theReply);
  558.                         }
  559.                     else
  560.                         gUseSystemDirection = !gUseSystemDirection;            
  561.                 break;                
  562.  
  563.                 case cAppleEventRouting:
  564.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  565.                         {
  566.                             DescType theAERouting;
  567.                                 
  568.                             if (gAppleEventRouting == routeToDoc)
  569.                                 theAERouting = kAERouteToView;
  570.                             else if(gAppleEventRouting == routeToView)
  571.                                 theAERouting = kAERouteToDoc;                            
  572.                             
  573.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  574.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pAERouting);
  575.                             CTempDesc theNewValue;
  576.                             theNewValue.PutEnum(theAERouting);
  577.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  578.                             TAppleEvent * theReply = theEvent -> Send();
  579.                             FreeIfObject(theEvent);
  580.                             FreeIfObject(theReply);
  581.                         }
  582.                     else
  583.                         {
  584.                             if (gAppleEventRouting == routeToDoc)
  585.                                 gAppleEventRouting = routeToView;
  586.                             else if(gAppleEventRouting == routeToView)
  587.                                 gAppleEventRouting = routeToDoc;
  588.                         }                        
  589.                 break;
  590.                                 
  591. #if qDebug
  592.                 case cCountObjects:
  593.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  594.                         {
  595.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  596.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pObjectCountingEnabled);
  597.                             CTempDesc theNewValue;
  598.                             theNewValue.PutBoolean(!gObjectCountingEnabled);
  599.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  600.                             TAppleEvent * theReply = theEvent -> Send();
  601.                             FreeIfObject(theEvent);
  602.                             FreeIfObject(theReply);
  603.                         }
  604.                     else
  605.                         gObjectCountingEnabled = !gObjectCountingEnabled;        
  606.                 break;
  607.  
  608.                 case cResetObjectCount:
  609.                     {
  610.                         TResetObjectCountCommand* aResetObjectCountCommand = new TResetObjectCountCommand;
  611.                         aResetObjectCountCommand -> IResetObjectCountCommand();
  612.                         if (gSendAppleEvents)
  613.                             aResetObjectCountCommand -> fUseAppleEvent = TRUE;
  614.                         this -> PostCommand(aResetObjectCountCommand);
  615.                     }
  616.                 break;
  617.                 
  618.                 case cPrintBaseClassInfo:
  619.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  620.                         {
  621.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  622.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pPrBaseClassInfo);
  623.                             CTempDesc theNewValue;
  624.                             theNewValue.PutBoolean(!gPrintBaseClassInfo);
  625.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  626.                             TAppleEvent * theReply = theEvent -> Send();
  627.                             FreeIfObject(theEvent);
  628.                         FreeIfObject(theReply);
  629.                             }
  630.                     else        
  631.                         gPrintBaseClassInfo = !gPrintBaseClassInfo;
  632.                 break;
  633.  
  634.                 case cPrintMacAppClassInfo:
  635.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  636.                         {
  637.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  638.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pPrMacAppClassInfo);
  639.                             CTempDesc theNewValue;
  640.                             theNewValue.PutBoolean(!gPrintMacAppClassInfo);
  641.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  642.                             TAppleEvent * theReply = theEvent -> Send();
  643.                             FreeIfObject(theEvent);
  644.                             FreeIfObject(theReply);
  645.                         }
  646.                     else                
  647.                         gPrintMacAppClassInfo = !gPrintMacAppClassInfo;
  648.                 break;
  649.  
  650.                 case cPrintAppClassInfo:
  651.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  652.                         {
  653.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  654.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pPrAppClassInfo);
  655.                             CTempDesc theNewValue;
  656.                             theNewValue.PutBoolean(!gPrintAppClassInfo);
  657.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  658.                             TAppleEvent * theReply = theEvent -> Send();
  659.                             FreeIfObject(theEvent);
  660.                             FreeIfObject(theReply);
  661.                         }
  662.                     else    
  663.                         gPrintAppClassInfo = !gPrintAppClassInfo;
  664.                 break;
  665.  
  666.                 case cAppUserFlag1:
  667.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  668.                         {
  669.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  670.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pSetAppUserFlag1);
  671.                             CTempDesc theNewValue;
  672.                             theNewValue.PutBoolean(!gAppUserFlag1);
  673.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  674.                             TAppleEvent * theReply = theEvent -> Send();
  675.                             FreeIfObject(theEvent);
  676.                             FreeIfObject(theReply);
  677.                         }
  678.                     else    
  679.                         gAppUserFlag1 = !gAppUserFlag1;
  680.                 break;
  681.                     
  682.                 case cAppUserFlag2:
  683.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  684.                         {
  685.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  686.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pSetAppUserFlag2);
  687.                             CTempDesc theNewValue;
  688.                             theNewValue.PutBoolean(!gAppUserFlag2);
  689.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  690.                             TAppleEvent * theReply = theEvent -> Send();
  691.                             FreeIfObject(theEvent);
  692.                             FreeIfObject(theReply);
  693.                         }
  694.                     else                    
  695.                         gAppUserFlag2 = !gAppUserFlag2;
  696.                 break;
  697.                 
  698.                 case cAppUserFlag3:
  699.                     if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && gSendAppleEvents)
  700.                         {
  701.                             TSetPropertyEvent *theEvent = new TSetPropertyEvent;
  702.                             theEvent -> ISetPropertyEvent(gServerAddress, kAENoReply, this, pSetAppUserFlag3);
  703.                             CTempDesc theNewValue;
  704.                             theNewValue.PutBoolean(!gAppUserFlag3);
  705.                             theEvent -> WriteParameter(keyAEData, theNewValue);
  706.                             TAppleEvent * theReply = theEvent -> Send();
  707.                             FreeIfObject(theEvent);
  708.                             FreeIfObject(theReply);
  709.                         }
  710.                     else    
  711.                         gAppUserFlag3 = !gAppUserFlag3;
  712.                 break;
  713.             
  714. #endif
  715.  
  716.                 default:
  717.                     Inherited::DoMenuCommand(aCommandNumber);
  718.                 break;
  719.             }    //end switch
  720.         
  721. }
  722. //----------------------------------------------------------------------------------------
  723. //    TTwistDownApp::AddWindowToWindowsMenuList
  724. //----------------------------------------------------------------------------------------    
  725. #pragma segment ARes
  726. void     TTwistDownApp::AddWindowToWindowsMenuList(TWindow* windowToAdd)
  727. {
  728. if (fWindowsMenuList && (fWindowsMenuList->GetIdentityItemNo(windowToAdd) == 0))
  729.     fWindowsMenuList->Insert(windowToAdd);
  730.  
  731. }
  732. //----------------------------------------------------------------------------------------
  733. //    TTwistDownApp::RemoveWindowFromWindowsMenuList
  734. //----------------------------------------------------------------------------------------    
  735. #pragma segment AClose
  736. void     TTwistDownApp::RemoveWindowFromWindowsMenuList(TWindow* windowToRemove)
  737. {
  738.     if (fWindowsMenuList && windowToRemove)
  739.         fWindowsMenuList->Delete(windowToRemove);
  740.  
  741. }
  742. //----------------------------------------------------------------------------------------
  743. //    TTwistDownApp::CountWindowsInList
  744. //----------------------------------------------------------------------------------------    
  745. #pragma segment ARes
  746. short TTwistDownApp::CountWindowsInList()
  747. {
  748.     MAVolatileInit(short, openWindows, 0);
  749.     CWindowsMenuListIterator iter(this);
  750.  
  751.     if (!(fWindowsMenuList -> IsEmpty()))
  752.         for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
  753.             if (aWindow)
  754.                 ++openWindows;
  755.             
  756.     return openWindows;
  757.  
  758. }
  759. //----------------------------------------------------------------------------------------
  760. //    TTwistDownApp::DoMakeSplashScreen
  761. //----------------------------------------------------------------------------------------    
  762. #pragma segment AInit
  763. TWindow* TTwistDownApp::DoMakeSplashScreen()
  764. {
  765.  
  766. TWindow* theSplashScreenWindow = NULL;
  767.  
  768. CStr255 aString;
  769.  
  770. this -> GetApplicationName(aString);
  771. MAParamText("^programName", aString);
  772.  
  773. VersRecHndl vers1Info = (VersRecHndl)::GetResource(kVersInfoType, kVers1InfoID);
  774.  
  775. if (vers1Info)
  776.     aString = (**vers1Info).shortVersion;
  777. else
  778.     aString = gEmptyString;
  779.  
  780. MAParamText("^verStr", aString);
  781.  
  782. FailInfo fi;
  783. Try(fi)
  784.     {
  785.         theSplashScreenWindow = gViewServer -> NewTemplateWindow(kAboutBoxWindowID, NULL);
  786.  
  787.         FailNIL(theSplashScreenWindow);
  788.  
  789.         if (theSplashScreenWindow)
  790.             {
  791.                 TStaticText* theProgramNameStaticText = NULL;
  792.                 TStaticText* theCopyrightStaticText = NULL;
  793.     
  794.     
  795.                 theProgramNameStaticText = (TStaticText*) (theSplashScreenWindow -> FindSubView(kAboutProgNameViewID));
  796.                 theCopyrightStaticText = (TStaticText*) (theSplashScreenWindow -> FindSubView(kAboutCopyrightViewID));
  797.     
  798.  
  799.                 TButton* theOKButton = NULL;
  800.                 theOKButton = (TButton*) (theSplashScreenWindow -> FindSubView('ok  '));
  801.                 theSplashScreenWindow -> RemoveSubView(theOKButton);
  802.                 
  803.                 //To create a memory leak, comment out the following statement.        
  804.                 theOKButton = (TButton*)(FreeIfObject(theOKButton));    //otherwise would be orphaned.
  805.                         
  806.                 TDialogBehavior* itsDialogBehavior = theSplashScreenWindow -> GetDialogBehavior();
  807.                 if (itsDialogBehavior)
  808.                     theSplashScreenWindow -> RemoveBehavior (itsDialogBehavior);
  809.                     
  810.                 //To create a memory leak, comment out the following statement.                                
  811.                 itsDialogBehavior = (TDialogBehavior*)(FreeIfObject(itsDialogBehavior));    //otherwise would be orphaned.
  812.  
  813.     
  814.                 TextStyle theTextStyle = gApplicationStyle;
  815.                 CStr255 theFontName = "New Century Schoolbook";
  816.                 short theFontNumber;
  817.                 GetFNum(theFontName, &theFontNumber);
  818.     
  819.                 short theFontSize = 24;
  820.                 if (theFontNumber != 0)
  821.                     theTextStyle.tsFont = theFontNumber;
  822.  
  823.                 theTextStyle.tsSize = theFontSize;
  824.         
  825.                 CRGBColor theColor = gRGBBlue;
  826.     
  827.                 theProgramNameStaticText -> InstallTextStyle(theTextStyle, kDontRedraw);
  828.                 theProgramNameStaticText -> InstallColor(theColor, kDontRedraw);
  829.     
  830.                 theFontSize = 12;
  831.                 theTextStyle.tsSize = theFontSize;
  832.                 theCopyrightStaticText -> InstallTextStyle(theTextStyle, kDontRedraw);
  833.                 theCopyrightStaticText -> InstallColor(theColor, kDontRedraw);
  834.             }
  835.         fi.Success();
  836.     }
  837. else
  838.     {
  839.         theSplashScreenWindow = (TWindow*)(FreeIfObject(theSplashScreenWindow));
  840.         theSplashScreenWindow = NULL;
  841.         fi.ReSignal();
  842.     }
  843.     
  844. return theSplashScreenWindow;
  845.     
  846. }
  847. //----------------------------------------------------------------------------------------
  848. //    TTwistDownApp::DoMakeAboutBox
  849. //----------------------------------------------------------------------------------------    
  850. #pragma segment MAAboutApp
  851. TWindow* TTwistDownApp::DoMakeAboutBox()
  852. {
  853.  
  854. TWindow* theAboutBoxWindow = NULL;
  855.  
  856. CStr255 aString;
  857.  
  858. this -> GetApplicationName(aString);
  859. MAParamText("^programName", aString);
  860.  
  861. VersRecHndl vers1Info = (VersRecHndl)::GetResource(kVersInfoType, kVers1InfoID);
  862.  
  863. if (vers1Info)
  864.     aString = (**vers1Info).shortVersion;
  865. else
  866.     aString = gEmptyString;
  867.  
  868. MAParamText("^verStr", aString);
  869.  
  870. FailInfo fi;
  871. Try(fi)
  872.     {
  873.         theAboutBoxWindow = gViewServer -> NewTemplateWindow(kAboutBoxWindowID, NULL);
  874.  
  875.         FailNIL(theAboutBoxWindow);
  876.  
  877.         if (theAboutBoxWindow)
  878.             {
  879.                 TStaticText* theProgramNameStaticText = NULL;
  880.                 TStaticText* theCopyrightStaticText = NULL;
  881.     
  882.     
  883.                 theProgramNameStaticText = (TStaticText*) (theAboutBoxWindow -> FindSubView(kAboutProgNameViewID));
  884.                 theCopyrightStaticText = (TStaticText*) (theAboutBoxWindow -> FindSubView(kAboutCopyrightViewID));
  885.  
  886.                 TextStyle theTextStyle = gApplicationStyle;
  887.                 CStr255 theFontName = "New Century Schoolbook";
  888.                 short theFontNumber;
  889.                 GetFNum(theFontName, &theFontNumber);
  890.     
  891.                 short theFontSize = 24;
  892.                 if (theFontNumber != 0)
  893.                     theTextStyle.tsFont = theFontNumber;
  894.                 
  895.                 theTextStyle.tsSize = theFontSize;
  896.         
  897.                 CRGBColor theColor = gRGBBlue;
  898.     
  899.                 theProgramNameStaticText -> InstallTextStyle(theTextStyle, kDontRedraw);
  900.                 theProgramNameStaticText -> InstallColor(theColor, kDontRedraw);
  901.     
  902.                 theFontSize = 12;
  903.                 theTextStyle.tsSize = theFontSize;
  904.                 theCopyrightStaticText -> InstallTextStyle(theTextStyle, kDontRedraw);
  905.                 theCopyrightStaticText -> InstallColor(theColor, kDontRedraw);
  906.             }
  907.         fi.Success();
  908.     }
  909. else
  910.     {
  911.         theAboutBoxWindow = (TWindow*)(FreeIfObject(theAboutBoxWindow));
  912.         fi.ReSignal();
  913.     }
  914.     
  915. return theAboutBoxWindow;
  916.     
  917. }
  918. //----------------------------------------------------------------------------------------
  919. //    TTwistDownApp::DoAboutBox
  920. //----------------------------------------------------------------------------------------    
  921. #pragma segment MAAboutApp
  922. void TTwistDownApp::DoAboutBox()
  923. {
  924. TWindow* theAboutBoxWindow = NULL;
  925.  
  926. FailInfo fi;
  927. Try(fi)
  928.     {
  929.         theAboutBoxWindow = this -> DoMakeAboutBox();
  930.                     
  931.         if (theAboutBoxWindow)
  932.             {
  933.                 theAboutBoxWindow -> PoseModally();    
  934.                 theAboutBoxWindow -> CloseAndFree();
  935.             }
  936.         fi.Success();
  937.     }
  938. else
  939.     {
  940.         fi.ReSignal();
  941.     }
  942.  
  943. }
  944. //----------------------------------------------------------------------------------------
  945. // TTwistDownApp::GetStandardFileParameters: 
  946. //----------------------------------------------------------------------------------------
  947. #pragma segment AOpen
  948. void TTwistDownApp::GetStandardFileParameters(CommandNumber itsCommandNumber,ProcPtr& fileFilter,
  949.                                              TypeListHandle& typeList,short& dlgID,CPoint& where,ProcPtr& dlgHook,
  950.                                              ProcPtr& modalFilter,Ptr& activeList,ProcPtr& activateProc,
  951.                                              StandardFileReply* /*reply*/, void*& yourDataPtr)
  952. {
  953.     dlgID = sfGetDialogID;
  954.     where = kBestSystemLocation;
  955.  
  956.     this->GetFileTypeList(itsCommandNumber, typeList);
  957.  
  958.     fileFilter = (ProcPtr)gFileFilterYDProcPtr;
  959.     dlgHook = (ProcPtr)gDlgHookYDProcPtr;
  960.     modalFilter = (ProcPtr)gModalFilterYDProcPtr;
  961.  
  962.     activeList = NULL;
  963.     activateProc = NULL;
  964.     yourDataPtr = NULL;
  965. }
  966. //----------------------------------------------------------------------------------------
  967. // TTwistDownApp::DoOpen: 
  968. //----------------------------------------------------------------------------------------
  969. #pragma segment MAScriptingRes
  970. void TTwistDownApp::DoOpen(CommandNumber theCmdNumber)
  971. {
  972.  
  973. TList* aVolumeList = NULL;    // passed by address
  974.         
  975. if (this -> ChooseVolume(theCmdNumber, &aVolumeList))
  976.     {
  977.         TOVolumeCommand* anOVolumeCommand = new TOVolumeCommand;
  978.         anOVolumeCommand -> IOVolumeCommand(theCmdNumber, aVolumeList);
  979.         if (gSendAppleEvents)
  980.             anOVolumeCommand -> fUseAppleEvent = TRUE;
  981.         this -> PostCommand(anOVolumeCommand);
  982.     }    
  983.  
  984. }
  985. //----------------------------------------------------------------------------------------
  986. // TTwistDownApp::DoScriptCommand:     Scripting Support
  987. //----------------------------------------------------------------------------------------
  988. #pragma segment MAScriptingRes
  989. void TTwistDownApp::DoScriptCommand(CommandNumber    aCommandNumber, TAppleEvent* message, TAppleEvent* reply)
  990. {
  991.     switch (aCommandNumber)
  992.     {
  993.         case cFinderOpen:
  994.             {
  995.                 TOVolumeCommand * anOVolumeCommand = new TOVolumeCommand;
  996.                 anOVolumeCommand->IOVolumeCommand(aCommandNumber, message->fMessage, reply->fMessage);
  997.                 this->PostCommand(anOVolumeCommand);
  998.             }
  999.             break;
  1000.  
  1001. #if qDebug
  1002.         case cResetObjectCount:
  1003.             {
  1004.                 TResetObjectCountCommand* aResetObjectCountCommand = new TResetObjectCountCommand;
  1005.                 aResetObjectCountCommand -> IResetObjectCountCommand(message -> fMessage, reply -> fMessage);
  1006.                 this -> PostCommand(aResetObjectCountCommand);
  1007.             }
  1008.             break;
  1009. #endif
  1010.  
  1011.         default:
  1012.             {
  1013.                 Inherited::DoScriptCommand(aCommandNumber, message, reply);
  1014.             }
  1015.             break;
  1016.     }
  1017. }
  1018. //----------------------------------------------------------------------------------------
  1019. // TTwistDownApp::CountContainedObjects: 
  1020. //----------------------------------------------------------------------------------------
  1021. #pragma segment MAScriptingRes
  1022.  
  1023. long TTwistDownApp::CountContainedObjects(DescType desiredType)
  1024. {
  1025.     long result = 0;
  1026.  
  1027.     switch (desiredType)
  1028.     {
  1029.         case cTwistDownView:
  1030.             {            
  1031.                 CNoGhostDocsIterator iter(this);
  1032.                 for (TDocument * aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
  1033.                     if (aDocument -> GetOMClass() == cDocument)
  1034.                         result++;
  1035.             }
  1036.             break;
  1037.  
  1038.         default:
  1039.             {                
  1040.                 result = Inherited::CountContainedObjects(desiredType);
  1041.             }
  1042.             break;
  1043.     }
  1044.  
  1045.     return result;
  1046. }
  1047. //----------------------------------------------------------------------------------------
  1048. // TTwistDownApp::GetContainedObject: 
  1049. //----------------------------------------------------------------------------------------
  1050. #pragma segment OSLDispatchRes
  1051. MScriptableObject* TTwistDownApp::GetContainedObject(DescType desiredType,
  1052.                                                     DescType selectionForm,const CAEDesc& selectionData)
  1053. {
  1054.  
  1055.     MScriptableObject* result = NULL;
  1056.     TTwistDownView* theTwistDownView = NULL;
  1057.     TTwistDownDocument* theTwistDownDocument = NULL;
  1058.     
  1059.     if (desiredType == cTwistDownView && selectionForm == formName)
  1060.     {
  1061.         CStr255 theName;
  1062.         selectionData.GetString(theName);
  1063.         CNoGhostDocsIterator iter(this);
  1064.         for (TDocument* aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
  1065.             {
  1066.                 if (aDocument != NULL)
  1067.                     {
  1068.                         CStr255 name = gEmptyString;
  1069.                         aDocument -> GetTitle(name);
  1070.                         if (name == theName)
  1071.                             {
  1072.                                 theTwistDownDocument = (TTwistDownDocument*)aDocument;
  1073.                                 theTwistDownView = theTwistDownDocument -> fTwistDownView;
  1074.                                 result = theTwistDownView;
  1075.                                 return result;
  1076.                             }
  1077.                     }
  1078.             }
  1079.                         
  1080.     }
  1081.     else if (desiredType == cDocument && selectionForm == formName)
  1082.     {
  1083. //Note: MacApp 3.3.1 TApplication::GetContainedObject dose not work if a script
  1084. //attempts to get a document that does not exist. In the case where there are
  1085. //no open documents, the result is an access fault. Therefore, I'm using the
  1086. //following substitute code.
  1087.         CStr255    theName;
  1088.         selectionData.GetString(theName);        
  1089.         CNoGhostDocsIterator    iter(this);
  1090.         
  1091.         for (TDocument* aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
  1092.             {
  1093.                 if (aDocument != NULL)
  1094.                     {
  1095.                         CStr255 name = gEmptyString;
  1096.                         aDocument -> GetTitle(name);
  1097.                         if (name == theName)
  1098.                             {                    
  1099.                                 theTwistDownDocument = (TTwistDownDocument*)aDocument;
  1100.                                 result = theTwistDownDocument;
  1101.                                 return result;
  1102.                             }
  1103.                     }
  1104.             }
  1105.     }
  1106.     else
  1107.         {
  1108.             result = Inherited::GetContainedObject(desiredType, selectionForm, selectionData);
  1109.         }
  1110.     return result;
  1111. }
  1112.  
  1113. //----------------------------------------------------------------------------------------
  1114. // TTwistDownApp::GetSetPropertyInfo:        Scripting Support
  1115. //----------------------------------------------------------------------------------------
  1116. #pragma segment MAScriptingRes
  1117. void TTwistDownApp::GetSetPropertyInfo(DescType whichProperty,CommandNumber& cmdNum,
  1118.                                 Boolean& canUndo,Boolean& causesChange,TCommandHandler* &theContext)
  1119. {
  1120.  
  1121. switch(whichProperty)
  1122.     {
  1123.     
  1124.         case pShowInvisibleFiles:
  1125.             cmdNum = cShowInvisibleFiles;
  1126.             canUndo = FALSE;
  1127.             causesChange = FALSE;
  1128.             theContext = this;
  1129.             break;
  1130.             
  1131.         case pUseSystemDirection:
  1132.             cmdNum = cUseSystemDirection;
  1133.             canUndo = FALSE;
  1134.             causesChange = FALSE;
  1135.             theContext = this;
  1136.             break;
  1137.  
  1138.         case pSendAppleEvents:
  1139.             cmdNum = cSendAppleEvents;
  1140.             canUndo = FALSE;
  1141.             causesChange = FALSE;
  1142.             theContext = this;
  1143.             break;
  1144.  
  1145.         case pFailHere:
  1146.             cmdNum = cFailHere;
  1147.             canUndo = FALSE;
  1148.             causesChange = FALSE;
  1149.             theContext = this;
  1150.             break;
  1151.  
  1152.         case pUnlimitedDocs:
  1153.             cmdNum = cAllowUnlimitedDocs;
  1154.             canUndo = FALSE;
  1155.             causesChange = FALSE;
  1156.             theContext = this;
  1157.             break;
  1158.             
  1159.         case pAERouting:
  1160.             cmdNum = cAppleEventRouting;
  1161.             canUndo = FALSE;
  1162.             causesChange = FALSE;
  1163.             theContext = this;
  1164.             break;
  1165.             
  1166. #if qDebug
  1167.         case pObjectCountingEnabled:
  1168.             cmdNum = cCountObjects;
  1169.             canUndo = FALSE;
  1170.             causesChange = FALSE;
  1171.             theContext = this;
  1172.             break;
  1173.             
  1174.         case pPrBaseClassInfo:
  1175.             cmdNum = cPrintBaseClassInfo;
  1176.             canUndo = FALSE;
  1177.             causesChange = FALSE;
  1178.             theContext = this;
  1179.             break;
  1180.             
  1181.         case pPrMacAppClassInfo:
  1182.             cmdNum = cPrintMacAppClassInfo;
  1183.             canUndo = FALSE;
  1184.             causesChange = FALSE;
  1185.             theContext = this;
  1186.             break;
  1187.             
  1188.         case pPrAppClassInfo:
  1189.             cmdNum = cPrintAppClassInfo;
  1190.             canUndo = FALSE;
  1191.             causesChange = FALSE;
  1192.             theContext = this;
  1193.             break;
  1194.             
  1195.         case pSetAppUserFlag1:
  1196.             cmdNum = cAppUserFlag1;
  1197.             canUndo = FALSE;
  1198.             causesChange = FALSE;
  1199.             theContext = this;
  1200.             break;
  1201.             
  1202.         case pSetAppUserFlag2:
  1203.             cmdNum = cAppUserFlag2;
  1204.             canUndo = FALSE;
  1205.             causesChange = FALSE;
  1206.             theContext = this;
  1207.             break;
  1208.             
  1209.         case pSetAppUserFlag3:
  1210.             cmdNum = cAppUserFlag3;
  1211.             canUndo = FALSE;
  1212.             causesChange = FALSE;
  1213.             theContext = this;
  1214.             break;
  1215. #endif
  1216.         
  1217.         default:
  1218.             Inherited::GetSetPropertyInfo(whichProperty, cmdNum, canUndo, causesChange, theContext);
  1219.             break;
  1220.     }
  1221. }
  1222. //----------------------------------------------------------------------------------------
  1223. // TTwistDownApp::SetObjectProperty: 
  1224. //----------------------------------------------------------------------------------------
  1225. #pragma segment MAScriptingRes
  1226. void TTwistDownApp::SetObjectProperty(const CAEDesc& thePropertyValue,
  1227.                                      DescType whichProperty)
  1228. {
  1229.     Boolean newValue = FALSE;
  1230.     CAEDesc localPropValue = thePropertyValue;
  1231.     switch (whichProperty)
  1232.     {
  1233.         case pShowInvisibleFiles:
  1234.             newValue = thePropertyValue.GetBoolean();                    
  1235.             fShowInvisibleFiles = newValue;            
  1236.             break;
  1237.  
  1238.         case pUseSystemDirection:
  1239.             newValue = thePropertyValue.GetBoolean();                    
  1240.             gUseSystemDirection = newValue;            
  1241.             break;        
  1242.  
  1243.         case pSendAppleEvents:
  1244.             newValue = thePropertyValue.GetBoolean();                    
  1245.             gSendAppleEvents = newValue;            
  1246.             break;        
  1247.  
  1248.         case pFailHere:
  1249.             newValue = thePropertyValue.GetBoolean();                    
  1250.             gFailHere = newValue;            
  1251.             break;
  1252.  
  1253.         case pUnlimitedDocs:
  1254.             newValue = thePropertyValue.GetBoolean();                    
  1255.             fAllowUnlimitedDocs = newValue;            
  1256.             break;
  1257.             
  1258.         case pAERouting:
  1259.             DescType theAERouting = thePropertyValue.GetEnum();    
  1260.             if (theAERouting == kAERouteToDoc)
  1261.                 gAppleEventRouting = routeToDoc;
  1262.             else 
  1263.                 gAppleEventRouting = routeToView;
  1264.             break;    
  1265.  
  1266. #if qDebug            
  1267.         case pObjectCountingEnabled:
  1268.             newValue = thePropertyValue.GetBoolean();
  1269.             gObjectCountingEnabled = newValue;                    
  1270.             break;
  1271.             
  1272.         case pPrBaseClassInfo:
  1273.             newValue = thePropertyValue.GetBoolean();            
  1274.             gPrintBaseClassInfo = newValue;            
  1275.             break;
  1276.             
  1277.         case pPrMacAppClassInfo:
  1278.             newValue = thePropertyValue.GetBoolean();            
  1279.             gPrintMacAppClassInfo = newValue;
  1280.             break;
  1281.             
  1282.         case pPrAppClassInfo:
  1283.             newValue = thePropertyValue.GetBoolean();            
  1284.             gPrintAppClassInfo = newValue;            
  1285.             break;
  1286.             
  1287.         case pSetAppUserFlag1:    
  1288.             newValue = thePropertyValue.GetBoolean();            
  1289.             gAppUserFlag1 = newValue;            
  1290.             break;
  1291.             
  1292.         case pSetAppUserFlag2:
  1293.             newValue = thePropertyValue.GetBoolean();            
  1294.             gAppUserFlag2 = newValue;            
  1295.             break;
  1296.             
  1297.         case pSetAppUserFlag3:
  1298.             newValue = thePropertyValue.GetBoolean();            
  1299.             gAppUserFlag3 = newValue;            
  1300.             break;        
  1301. #endif
  1302.         
  1303.         default:
  1304.             Inherited::SetObjectProperty(thePropertyValue, whichProperty);
  1305.             break;
  1306.     }
  1307. }
  1308. //----------------------------------------------------------------------------------------
  1309. // TTwistDownApp::GetObjectProperty: 
  1310. //----------------------------------------------------------------------------------------
  1311. #pragma segment MAScriptingRes
  1312.  
  1313. Boolean TTwistDownApp::GetObjectProperty(CAEDesc& thePropertyValue,DescType whichProperty,const CAEDesc& desiredType)
  1314. {
  1315.  
  1316. Boolean hasProperty = TRUE;
  1317.  
  1318.     FailInfo fi;
  1319.     Try(fi)
  1320.     {
  1321.         switch (whichProperty)
  1322.         {
  1323.             case pShowInvisibleFiles:
  1324.                 thePropertyValue.PutBoolean(fShowInvisibleFiles);
  1325.                 break;
  1326.  
  1327.             case pUseSystemDirection:
  1328.                 thePropertyValue.PutBoolean(gUseSystemDirection);
  1329.                 break;
  1330.  
  1331.             case pSendAppleEvents:
  1332.                 thePropertyValue.PutBoolean(gSendAppleEvents);
  1333.                 break;
  1334.  
  1335.             case pFailHere:
  1336.                 thePropertyValue.PutBoolean(gFailHere);
  1337.                 break;
  1338.                 
  1339.             case pUnlimitedDocs:
  1340.                 thePropertyValue.PutBoolean(fAllowUnlimitedDocs);
  1341.                 break;
  1342.                 
  1343.             case pAERouting:
  1344.                 DescType theAERouting;
  1345.                 if (gAppleEventRouting == routeToDoc)
  1346.                     theAERouting = kAERouteToDoc;
  1347.                 else
  1348.                     theAERouting = kAERouteToView;    
  1349.                     
  1350.                 thePropertyValue.PutEnum(theAERouting);
  1351.                 break;
  1352.  
  1353. #if qDebug
  1354.             case pObjectCountingEnabled:
  1355.                 thePropertyValue.PutBoolean(gObjectCountingEnabled);
  1356.                 break;    
  1357.                 
  1358.             case pPrBaseClassInfo:
  1359.                 thePropertyValue.PutBoolean(gPrintBaseClassInfo);
  1360.                 break;
  1361.                 
  1362.             case pPrMacAppClassInfo:
  1363.                 thePropertyValue.PutBoolean(gPrintMacAppClassInfo);
  1364.                 break;
  1365.                 
  1366.             case pPrAppClassInfo:
  1367.                 thePropertyValue.PutBoolean(gPrintAppClassInfo);
  1368.                 break;
  1369.                 
  1370.             case pSetAppUserFlag1:
  1371.                 thePropertyValue.PutBoolean(gAppUserFlag1);
  1372.                 break;
  1373.                 
  1374.             case pSetAppUserFlag2:
  1375.                 thePropertyValue.PutBoolean(gAppUserFlag2);
  1376.                 break;
  1377.                 
  1378.             case pSetAppUserFlag3:    
  1379.                 thePropertyValue.PutBoolean(gAppUserFlag3);
  1380.                 break;
  1381. #endif
  1382.  
  1383.             default:
  1384.                 hasProperty = Inherited::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
  1385.                 break;
  1386.         }
  1387.         fi.Success();
  1388.     }
  1389.     else
  1390.     {
  1391.         // we failed while trying to get the property
  1392.         hasProperty = FALSE;
  1393.         
  1394.         // Don't ReSignal
  1395.     }
  1396.     return hasProperty;
  1397. }
  1398.  
  1399. //========================================================================================
  1400. // CLASS TVolumesCommand    analog of TFilesCommand
  1401. //========================================================================================
  1402. #undef Inherited
  1403. #define Inherited TServerCommand
  1404.  
  1405. #pragma segment ASelCommand
  1406. MA_DEFINE_CLASS_M1(TVolumesCommand, Inherited);
  1407.  
  1408. //----------------------------------------------------------------------------------------
  1409. // TVolumesCommand constructor
  1410. //----------------------------------------------------------------------------------------
  1411. #pragma segment ASelCommand
  1412. TVolumesCommand::TVolumesCommand()
  1413. {
  1414.     fCausesChange = FALSE;
  1415.     fVolumeList = NULL;
  1416.  
  1417. #if qDebug
  1418. this -> PrintAppConstructorClassInfo();
  1419. #endif
  1420.  
  1421. }
  1422. //----------------------------------------------------------------------------------------
  1423. // TVolumesCommand::Free: 
  1424. //----------------------------------------------------------------------------------------
  1425. #pragma segment AClose
  1426. TVolumesCommand::~TVolumesCommand()
  1427. {
  1428.     fVolumeList = (TList*)FreeListIfObject(fVolumeList);
  1429. #if qDebug
  1430. this -> PrintAppDestructorClassInfo();
  1431. #endif
  1432.  
  1433. }
  1434. //----------------------------------------------------------------------------------------
  1435. // TVolumesCommand::IVolumesCommand: 
  1436. //----------------------------------------------------------------------------------------
  1437. #pragma segment ASelCommand
  1438. void TVolumesCommand::IVolumesCommand(CommandNumber itsCommandNumber,
  1439.                                   TList* theDocuments)
  1440. {
  1441.  
  1442.     this -> IServerCommand(itsCommandNumber, gApplication, kCantUndo, kDoesNotCauseChange, NULL);
  1443.     fVolumeList = theDocuments;
  1444.     
  1445. //----------------------------------------------------------------------------------------
  1446. // TVolumesCommand::IVolumesCommand: 
  1447. //----------------------------------------------------------------------------------------
  1448. #pragma segment ASelCommand
  1449. void TVolumesCommand::IVolumesCommand(CommandNumber itsCommandNumber,
  1450.                                   const AppleEvent& itsMessage,
  1451.                                   const AppleEvent& itsReply)    // override 
  1452. {
  1453.     fSuspendTheEvent = TRUE;    //For debugging fun and games, comment this out. Everything
  1454.                                                         //will work fine until you encounter low memory conditions
  1455.                                                         //and fail. Then all bets are off.
  1456.     this -> IServerCommand(itsCommandNumber, gApplication, kCantUndo, kDoesNotCauseChange, NULL,
  1457.                    itsMessage, itsReply);
  1458.     
  1459.     // Check to see what is in the direct object list
  1460.     this -> GetVolumesList();
  1461.  
  1462. }
  1463. //----------------------------------------------------------------------------------------
  1464. // TVolumesCommand::GetVolumesList:    analog of TFilesCommand::GetFilesList:
  1465. //----------------------------------------------------------------------------------------
  1466. #pragma segment ASelCommand
  1467. void TVolumesCommand::GetVolumesList()
  1468. {
  1469.  
  1470.     // Check to see what is in the direct object list
  1471.     CAEDesc directObj;
  1472.     FailOSErr(AEGetParamDesc(&fMessage->fMessage, keyDirectObject, typeAEList, directObj));
  1473.     long theCount = 0;
  1474.     FailOSErr(AECountItems(directObj, &theCount));
  1475.     if (theCount > 0)
  1476.     {
  1477.         // Get the first descriptor and see what type it is
  1478.         DescType theKey;
  1479.         CTempDesc theDesc;
  1480.  
  1481.         FailOSErr(AEGetNthDesc(directObj, 1, typeWildCard, &theKey, theDesc));
  1482.  
  1483.         MAVolatileInit(THandleList*, aHandleList, NULL);
  1484.         MAVolatileInit(TList*, aVolumeList, NULL);
  1485.         
  1486.         FailInfo outerFi;
  1487.         Try(outerFi)
  1488.         {
  1489.             aHandleList = new THandleList;
  1490.             aHandleList->IHandleList();
  1491.     
  1492.             FailInfo innerfi;
  1493.             Try(innerfi)
  1494.             {
  1495.                 aVolumeList = NewList();
  1496.         
  1497.                 fMessage->ReadHandleList(keyDirectObject, typeAlias, aHandleList);
  1498.         
  1499.                 // Block is necessary for correct failure handling
  1500.                 {
  1501.                     CHandleIterator iter(aHandleList);
  1502.         
  1503.                     for (Handle item = iter.FirstHandle(); iter.More(); item = iter.NextHandle())
  1504.                     {
  1505.                         MAVolatileInit(TVolume*, aVolume, NULL);
  1506.         
  1507.                         aVolume = gTwistDownApp -> DoMakeVolume();
  1508.     
  1509.                         FailInfo onemorefi;
  1510.                         Try(onemorefi)
  1511.                         {
  1512.                             FailOSErr(aVolume -> SpecifyWithAlias(AliasHandle(item)));
  1513.                             aVolumeList->InsertLast(aVolume);
  1514.                             onemorefi.Success();
  1515.                         }
  1516.                         else
  1517.                         {
  1518.                             aVolume = (TVolume*)FreeIfObject(aVolume);
  1519.                             onemorefi.ReSignal();
  1520.                         }
  1521.                         
  1522.                         aHandleList->Delete(item);        // Delete it from the list so if we fail
  1523.                                                         // we don't try to free it twice
  1524.                         item = DisposeIfHandle(item);
  1525.                     }
  1526.                 }
  1527.                 innerfi.Success();
  1528.             }
  1529.             else                                        // Recover
  1530.             {
  1531.  
  1532.                 if (aHandleList)
  1533.                     aHandleList->FreeList();
  1534.                     
  1535.                 if (aVolumeList)
  1536.                     aVolumeList->FreeList();
  1537.             
  1538.                 innerfi.ReSignal();
  1539.             }
  1540.             outerFi.Success();
  1541.         }
  1542.         else
  1543.         {
  1544.  
  1545.             this->Free();
  1546.             outerFi.ReSignal();
  1547.         }
  1548.     
  1549.         aHandleList->Free();                        // It is just a list of disposed handles…
  1550.     
  1551.         fVolumeList = aVolumeList;
  1552.         directObj.DisposeDesc();
  1553.     }
  1554.  
  1555. //========================================================================================
  1556. // CLASS TOVolumeCommand    analog of TODocCommand
  1557. //========================================================================================
  1558. #undef Inherited
  1559. #define Inherited TVolumesCommand
  1560.  
  1561. #pragma segment ASelCommand
  1562. MA_DEFINE_CLASS_M1(TOVolumeCommand, Inherited);
  1563.  
  1564. //----------------------------------------------------------------------------------------
  1565. // TOVolumeCommand: Empty constructor to satisfy the compiler.
  1566. //----------------------------------------------------------------------------------------
  1567. #pragma segment ASelCommand
  1568. TOVolumeCommand::TOVolumeCommand()
  1569. {
  1570. #if qDebug
  1571. this -> PrintAppConstructorClassInfo();
  1572. #endif
  1573. }
  1574. //----------------------------------------------------------------------------------------
  1575. // TOVolumeCommand destructor
  1576. //----------------------------------------------------------------------------------------
  1577. #pragma segment ASelCommand
  1578. TOVolumeCommand::~TOVolumeCommand()
  1579. {
  1580. #if qDebug
  1581. this -> PrintAppDestructorClassInfo();
  1582. #endif
  1583. }
  1584. //----------------------------------------------------------------------------------------
  1585. // TOVolumeCommand::IOVolumeCommand: 
  1586. //----------------------------------------------------------------------------------------
  1587. #pragma segment ASelCommand
  1588. void TOVolumeCommand::IOVolumeCommand(CommandNumber itsCommandNumber,
  1589.                                 TList* theDocuments)
  1590. {
  1591. this->IVolumesCommand(itsCommandNumber, theDocuments);
  1592. }
  1593. //----------------------------------------------------------------------------------------
  1594. // TOVolumeCommand::IOVolumeCommand: 
  1595. //----------------------------------------------------------------------------------------
  1596. #pragma segment ASelCommand
  1597. void TOVolumeCommand::IOVolumeCommand(CommandNumber itsCommandNumber, const AppleEvent& itsMessage, const AppleEvent& itsReply)
  1598. {
  1599. this->IVolumesCommand(itsCommandNumber, itsMessage, itsReply);
  1600. }
  1601. //----------------------------------------------------------------------------------------
  1602. // TOVolumeCommand::DoIt: 
  1603. //----------------------------------------------------------------------------------------
  1604. #pragma segment AOpen
  1605. void TOVolumeCommand::DoIt()
  1606. {
  1607.     gTwistDownApp -> OpenVolume(fIdentifier, fVolumeList);
  1608. }
  1609. //----------------------------------------------------------------------------------------
  1610. // TOVolumeCommand::MakeAppleEvent: 
  1611. //----------------------------------------------------------------------------------------
  1612. #pragma segment MACommandRes
  1613. TAppleEvent* TOVolumeCommand::MakeAppleEvent()
  1614. {
  1615.     MAVolatileInit(TAppleEvent*, theEvent, NULL);
  1616.     CTempDesc theList;
  1617.  
  1618.     FailInfo fi;
  1619.     Try(fi)
  1620.     {
  1621.         theEvent = new TAppleEvent;
  1622.         theEvent->IAppleEvent(kCoreEventClass, kAEOpenDocuments, gServerAddress, kAEWaitReply);
  1623.         theList.CreateList();
  1624.         {
  1625.             CObjectIterator iter(fVolumeList);
  1626.             for (TVolume * aVolume = (TVolume *)iter.FirstObject(); iter.More(); aVolume = (TVolume *)iter.NextObject())
  1627.             {
  1628.                 AliasHandle theAlias = NULL;
  1629.                 OSErr theErr = aVolume -> GetAlias(theAlias);
  1630.                 if (theErr == noErr)
  1631.                 {
  1632.                     CAEDesc theAliasDesc(typeAlias, (Handle)theAlias);
  1633.                     theList.PutListItem(0, theAliasDesc);
  1634.                 }
  1635.             }
  1636.         }
  1637.         theEvent->WriteParameter(keyDirectObject, theList);
  1638.         fi.Success();
  1639.     }
  1640.     else                                // Recover
  1641.     {
  1642.         theEvent = (TAppleEvent *)FreeIfObject(theEvent);
  1643.         fi.ReSignal();
  1644.     }
  1645.     return theEvent;
  1646. }
  1647. //========================================================================================
  1648. // CLASS TOpenVolumeCommand - old version, not used
  1649. //========================================================================================
  1650. #undef Inherited
  1651. #define Inherited TCommand
  1652.  
  1653. #pragma segment ASelCommand
  1654. MA_DEFINE_CLASS_M1(TOpenVolumeCommand, Inherited);
  1655.  
  1656. //----------------------------------------------------------------------------------------
  1657. // TOpenVolumeCommand: Empty constructor to satisfy the compiler. - old version
  1658. //----------------------------------------------------------------------------------------
  1659. #pragma segment ASelCommand
  1660. TOpenVolumeCommand::TOpenVolumeCommand()
  1661. {
  1662. fVolume = NULL;
  1663.  
  1664. #if qDebug
  1665. this -> PrintAppConstructorClassInfo();
  1666. #endif
  1667. }
  1668. //----------------------------------------------------------------------------------------
  1669. // TOpenVolumeCommand destructor - old version
  1670. //----------------------------------------------------------------------------------------
  1671. #pragma segment ASelCommand
  1672. TOpenVolumeCommand::~TOpenVolumeCommand()
  1673. {
  1674. fVolume = NULL;
  1675.  
  1676. #if qDebug
  1677. this -> PrintAppDestructorClassInfo();
  1678. #endif
  1679. }
  1680. //----------------------------------------------------------------------------------------
  1681. // TOpenVolumeCommand::IOpenVolumeCommand:  - old version
  1682. //----------------------------------------------------------------------------------------
  1683. #pragma segment ASelCommand
  1684. void TOpenVolumeCommand::IOpenVolumeCommand(CommandNumber itsCommandNumber,TVolume* theVolume)
  1685. {
  1686. this -> ICommand(itsCommandNumber, NULL,kCantUndo,kDoesNotCauseChange,NULL);
  1687. fVolume = theVolume;
  1688. }
  1689. //----------------------------------------------------------------------------------------
  1690. // TOpenVolumeCommand::DoIt:  - old version
  1691. //----------------------------------------------------------------------------------------
  1692. #pragma segment AOpen
  1693. void TOpenVolumeCommand::DoIt()
  1694. {
  1695.  
  1696.     gTwistDownApp -> OpenVolume(fIdentifier, fVolume);    
  1697.  
  1698. }
  1699.  
  1700. #if qDebug
  1701. //========================================================================================
  1702. // CLASS TResetObjectCountCommand
  1703. //========================================================================================
  1704. #undef Inherited
  1705. #define Inherited TServerCommand
  1706.  
  1707. #pragma segment ASelCommand
  1708. MA_DEFINE_CLASS_M1(TResetObjectCountCommand, Inherited);
  1709.  
  1710. //----------------------------------------------------------------------------------------
  1711. // TResetObjectCountCommand constructor
  1712. //----------------------------------------------------------------------------------------
  1713. #pragma segment ASelCommand
  1714. TResetObjectCountCommand::TResetObjectCountCommand()
  1715. {
  1716. #if qDebug
  1717. this -> PrintAppConstructorClassInfo();
  1718. #endif
  1719. }
  1720. //----------------------------------------------------------------------------------------
  1721. // TResetObjectCountCommand::Free: 
  1722. //----------------------------------------------------------------------------------------
  1723. #pragma segment AClose
  1724. TResetObjectCountCommand::~TResetObjectCountCommand()
  1725. {
  1726. #if qDebug
  1727. this -> PrintAppDestructorClassInfo();
  1728. #endif
  1729. }
  1730. //----------------------------------------------------------------------------------------
  1731. // TResetObjectCountCommand::IResetObjectCountCommand: 
  1732. //----------------------------------------------------------------------------------------
  1733. #pragma segment ASelCommand
  1734. void TResetObjectCountCommand::IResetObjectCountCommand()
  1735. {
  1736.     this -> IServerCommand(cResetObjectCount, gTwistDownApp, kCantUndo, kDoesNotCauseChange, NULL);
  1737. //----------------------------------------------------------------------------------------
  1738. // TResetObjectCountCommand::IResetObjectCountCommand: 
  1739. //----------------------------------------------------------------------------------------
  1740. #pragma segment ASelCommand
  1741. void TResetObjectCountCommand::IResetObjectCountCommand(const AppleEvent& itsMessage,const AppleEvent& itsReply)
  1742. {                                                                
  1743. fSuspendTheEvent = TRUE;    //For debugging fun and games, comment this out. Everything
  1744.                                                     //will work fine until you encounter low memory conditions
  1745.                                                     //and fail. Then all bets are off. Note that it must be set
  1746.                                                     //before IServerCommand is called.
  1747.                                                     
  1748. this -> IServerCommand(cResetObjectCount, gTwistDownApp, kCantUndo, kDoesNotCauseChange, NULL,
  1749.                    itsMessage, itsReply);
  1750.     
  1751. }
  1752. //----------------------------------------------------------------------------------------
  1753. // TResetObjectCountCommand::MakeAppleEvent: 
  1754. //----------------------------------------------------------------------------------------
  1755. #pragma segment ASelCommand
  1756. TAppleEvent* TResetObjectCountCommand::MakeAppleEvent()
  1757. {
  1758.     MAVolatileInit(TAppleEvent*, theResetObjectCountEvent, NULL);
  1759.     
  1760.     FailInfo fi;
  1761.         Try(fi)
  1762.         {
  1763.             theResetObjectCountEvent = new TAppleEvent;
  1764.             theResetObjectCountEvent -> IAppleEvent(kAETwistDownListsSuite, kAEResetObjectCountID,gServerAddress, kAENoReply);
  1765.             {
  1766.                 CTempDesc    directObjectDesc;
  1767.                 gTwistDownApp -> MakeObjectSpecifier(directObjectDesc, gTwistDownApp -> GetSpecifierForm());
  1768.                 theResetObjectCountEvent -> WriteParameter(keyDirectObject, directObjectDesc);
  1769.             }
  1770.             fi.Success();
  1771.         }
  1772.         else // Recover
  1773.         {
  1774.             theResetObjectCountEvent = (TAppleEvent *)FreeIfObject(theResetObjectCountEvent);
  1775.             fi.ReSignal();
  1776.         }
  1777.         
  1778.     return theResetObjectCountEvent;
  1779. }
  1780. //----------------------------------------------------------------------------------------
  1781. //    TResetObjectCountCommand::DoIt:    
  1782. //----------------------------------------------------------------------------------------
  1783. #pragma segment ADoCommand
  1784. void TResetObjectCountCommand::DoIt()
  1785. {
  1786. gObjectCount = 1;    //Must set to 1 to account for this object, TResetObjectCountCommand,
  1787.                                     //being freed. 
  1788. }
  1789. #endif
  1790. //========================================================================================
  1791. // CLASS TSplashScreenCommand
  1792. //========================================================================================
  1793. #undef Inherited
  1794. #define Inherited TCommand
  1795.  
  1796. #pragma segment AInit
  1797. MA_DEFINE_CLASS_M1(TSplashScreenCommand, Inherited);
  1798.  
  1799. //----------------------------------------------------------------------------------------
  1800. // TSplashScreenCommand::TSplashScreenCommand
  1801. //----------------------------------------------------------------------------------------
  1802. #pragma segment AInit
  1803. TSplashScreenCommand::TSplashScreenCommand()
  1804. {
  1805. fSplashScreenWindow = NULL;
  1806.  
  1807. #if qDebug
  1808. this -> PrintAppConstructorClassInfo();
  1809. #endif
  1810.  
  1811. }
  1812. //----------------------------------------------------------------------------------------
  1813. // TSplashScreenCommand destructor
  1814. //----------------------------------------------------------------------------------------
  1815. #pragma segment AInit
  1816. TSplashScreenCommand::~TSplashScreenCommand()
  1817. {
  1818. if (fSplashScreenWindow)
  1819.     fSplashScreenWindow = (TWindow*)(FreeIfObject(fSplashScreenWindow));
  1820.  
  1821. fSplashScreenWindow = NULL;
  1822.  
  1823. #if qDebug
  1824. this -> PrintAppDestructorClassInfo();
  1825. #endif
  1826.  
  1827. }
  1828. //----------------------------------------------------------------------------------------
  1829. // TSplashScreenCommand::ISplashScreenCommand: 
  1830. //----------------------------------------------------------------------------------------
  1831. #pragma segment AInit
  1832. void TSplashScreenCommand::ISplashScreenCommand(CommandNumber itsCommandNumber)
  1833. {                                
  1834. this -> ICommand(itsCommandNumber, NULL, kCantUndo, kDoesNotCauseChange, NULL);
  1835.  
  1836. FailInfo fi;
  1837. Try(fi)
  1838.     {
  1839.         fSplashScreenWindow = gTwistDownApp -> DoMakeSplashScreen();
  1840.         fi.Success();
  1841.     }
  1842. else
  1843.     {
  1844.         fSplashScreenWindow = (TWindow*)(FreeIfObject(fSplashScreenWindow));
  1845.         fi.ReSignal();
  1846.     }
  1847. }
  1848. //----------------------------------------------------------------------------------------
  1849. // TSplashScreenCommand::DoIt: 
  1850. //----------------------------------------------------------------------------------------
  1851. #pragma segment AInit
  1852. void TSplashScreenCommand::DoIt()
  1853. {
  1854.  
  1855. if (fSplashScreenWindow)
  1856.     {
  1857.         fSplashScreenWindow -> Open();
  1858.         fSplashScreenWindow -> Update();
  1859.  
  1860.         long theTickCount;
  1861.         Delay(60, &theTickCount);
  1862.         
  1863.         fSplashScreenWindow -> CloseAndFree();
  1864.         fSplashScreenWindow = NULL;
  1865.     }
  1866. }
  1867.  
  1868. #pragma segment Inline